﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Domain;
using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Tests.PresentationModel
{
    [TestClass]
    public class JobSubmissionPTOTests
    {
        [TestMethod]
        public void ShouldValidatePassocBTJob()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedDataSetId = 1,
                SelectedJobType = JobType.PassocBT,
                SelectedPermutationCount = 10000,
                SelectedPhenotype = "weight"
            };

            Assert.IsTrue(pto.Validate(), "Failed to validate");
        }

        [TestMethod]
        public void ShouldValidatePModelJob()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedDataSetId = 1,
                SelectedJobType = JobType.PModel,
                SelectedPermutationCount = 10000,
                SelectedPhenotype = "weight",
            };

            Assert.IsTrue(pto.Validate(), "Failed to validate");
        }

        [TestMethod]
        public void ShouldFailValidationIfDataSetIdNull()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedJobType = JobType.PModel,
                SelectedPermutationCount = 10000,
                SelectedPhenotype = "weight",
            };

            this.AssertErrorCount(pto, 1);
        }

        [TestMethod]
        public void ShouldFailValidationIfPermutationCountNull()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedDataSetId = 1,
                SelectedJobType = JobType.PassocBT,
                SelectedPhenotype = "weight"
            };

            this.AssertErrorCount(pto, 1);
        }

        [TestMethod]
        public void ShouldFailValidationIfJobTypeNull()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedDataSetId = 1,
                SelectedPermutationCount = 10000,
                SelectedPhenotype = "weight"
            };

            this.AssertErrorCount(pto, 1);
        }

        [TestMethod]
        public void ShouldFailValidationIfSelectedPhenotypeNull()
        {
            JobSubmissionPTO pto = new JobSubmissionPTO()
            {
                SelectedDataSetId = 1,
                SelectedJobType = JobType.PassocBT,
                SelectedPermutationCount = 10000,
            };

            this.AssertErrorCount(pto, 1);
        }

        private void AssertErrorCount(JobSubmissionPTO pto, int expectedErrors)
        {
            pto.ValidationChanged += (o, e) => { Assert.AreEqual(expectedErrors, e.ValidationErrors.Count); };
            pto.Validate();
        }
    }
}
